﻿using Application.Adapter;
using Application.Common.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TouchSocket.Core;
using TouchSocket.Sockets;

namespace Application.Plugins
{
    public class CustomClientPlugin: PluginBase,ITcpConnectedPlugin,ITcpReceivedPlugin<ISocketClient>
    {
        public Task OnTcpConnected(ITcpClientBase client, ConnectedEventArgs e)
        {
            return Task.CompletedTask;
            //throw new NotImplementedException();
        }


        public async Task OnTcpReceived(ISocketClient client, ReceivedDataEventArgs e)
        {
            ///模拟设备自动响应
            if (e.RequestInfo is BetweenAndRequestInfo myRequest)
            {
                if (myRequest.DataType == Domain.Enums.DataType.测试两个tcp)
                {

                    await Console.Out.WriteLineAsync("收到api命令22：" + Convert.ToHexString(myRequest.Body));

                    var apiData = ("A5" + Convert.ToHexString(myRequest.Body) + "5A");
                    client.Send(apiData.HexStringToByteArray());
                }
            }
        }
    }
}
